package com.dhnsoft;

public class 有效的括号 {
    public static void main(String[] args) {
        String s = "()[]{}";
        boolean valid = isValid(s);
        System.out.println(valid);
    }

    public static boolean isValid(String s) {
        if(s==""||s==null){
            return false;
        }
        s = s.replace("(","a");
        s = s.replace(")","a");
        s = s.replace("{","b");
        s = s.replace("}","b");
        s = s.replace("[","c");
        s = s.replace("]","c");
        boolean flag=false;
        char c;
        for (int i = 0;i<s.length();i+=2){
            c = s.charAt(i);
           if(c==s.charAt(i+1))flag = true;
           else{
               flag=false;
               break;
           }
        }
        return flag;
    }
}
